﻿using OnlineLicenseConsumer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net;
using System.Threading;

namespace TestProject1
{
    
    
    /// <summary>
    ///This is a test class for ConsumerTest and is intended
    ///to contain all ConsumerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ConsumerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetLeftTimes
        ///</summary>
        [TestMethod()]
        public void GetLeftTimesTest()
        {
            Consumer target = new Consumer();
            string id = string.Empty; //"1986109827";// string.Empty; 
            int actual = target.GetLeftTimes(id);
            Assert.IsTrue(actual > 0);
        }

        /// <summary>
        ///A test for BeginGetLeftTimes
        ///</summary>
        [TestMethod()]
        public void BeginGetLeftTimesTest()
        {
            Consumer target = new Consumer();
            DownloadStringCompletedEventHandler handler = CallBackHandler;
            string id = string.Empty;// "1986109827";
            target.BeginGetLeftTimes(handler,id);
            Thread.Sleep(30000);
            Assert.IsTrue(daysleft > 0);
        }
        int daysleft;
        void CallBackHandler(object sender, DownloadStringCompletedEventArgs e)
        {
            string result = e.Result;
            bool valid = int.TryParse(result, out daysleft);
        }

        /// <summary>
        ///A test for Cpu
        ///</summary>
        [TestMethod()]
        public void CpuTest()
        {
            Consumer target = new Consumer(); // TODO: Initialize to an appropriate value
            string actual;
            actual = target.Cpu;
            Assert.IsFalse(string.IsNullOrEmpty(actual));
        }

        /// <summary>
        ///A test for GetLeftSofaAmount
        ///</summary>
        [TestMethod()]
        public void GetLeftSofaAmountTest()
        {
            Consumer target = new Consumer(); // TODO: Initialize to an appropriate value
            int actual;
            actual = target.GetLeftSofaAmount();
            Assert.IsTrue( actual > 0 );
        }
    }
}
